package cn.qiyu5522.controller;


import cn.qiyu5522.domain.entity.Menu;
import cn.qiyu5522.domain.entity.ResponseResult;
import cn.qiyu5522.service.MenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author Tonkey
 * @since 2024-04-22
 */
@RestController
@RequestMapping("/system/menu")
public class MenuController {

    @Resource
    private MenuService menuService;

    @GetMapping("/list")
    public ResponseResult getList(@RequestParam(required = false) String status,
                                  @RequestParam(required = false) String menuName){
        return menuService.getList(status,menuName);
    }

    @GetMapping("/{id}")
    public ResponseResult getMenuById(@PathVariable Long id){
        return menuService.getMenuById(id);
    }

    @PostMapping
    public ResponseResult addMenu(@RequestBody Menu menu){
        return menuService.addMenu(menu);
    }

    @PutMapping
    public ResponseResult updateMenu(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }

    @DeleteMapping("/{menuId}")
    public ResponseResult deleteMenuById(@PathVariable Long menuId){
        return menuService.deleteMenuById(menuId);
    }

    @GetMapping("/treeselect")
    public ResponseResult getMenuTree(){
        return menuService.getMenuTree();
    }

    @GetMapping("/roleMenuTreeselect/{roleId}")
    public ResponseResult roleMenuTreeSelect(@PathVariable Long roleId){
        return menuService.roleMenuTreeSelect(roleId);
    }

}
